home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
math
/
eval.zip
/
EVAL.DOC
< prev
next >
Wrap
Text File
|
1996-05-14
|
8KB
|
234 lines
Eval v.1.0 for Clarion for Dos 3.1
(CL) CopyLeft 1996, Petr Langer
No Rights Reserved
What is it ?
------------
A small utility for evaluating mathematical expressions in CfD 3.1.
Have you ever needed to evaluate any mathematical expression defined by user,
but there were no easy way to do that ?
Then this utility may be useful for you.
How to use it
-------------
Eval is defined as Function and called with two parameters.
The first one is String(200) variable containing expression to evalute.
The second one is Byte variable "passed by address", which returns
an error code if Eval is not able to correctly finish it's job.
Eval returns result of computing as a type of Real.
Example:
--------------------------------------------------------------------------
Program
map
Module('Eval')
Eval(STRING,*BYTE),REAL
.
.
Expr String(20)
Err_code Byte
Result Real
Code
Expr = 'Sin(Pi/2)'
Result = Eval(Expr,Err_code)
if ~Err_code ! Err_code = 0 if everything is OK
... ! code for error handling
... ! Result = 0
else
show(,,Result,@n22.10)
.
--------------------------------------------------------------------------
You have to add this line to the Project ==> Module
Module Name : %clapfx%eval.lib
Module Type : Object/Library (Linker)
I included a very simple program called CALC.CLA
Functions defined in Eval
-------------------------
With one parameter :
SIN(x) - Sine
COS(x) - Cosine
TAN(x) - Tangens
COTG(x) - Cotangens
ASIN(x) - ArcSine
ACOS(x) - ArcCosine
ATAN(x) - ArcTangens
EXP(x) - e^x ( e is the Euler's number )
LOGE(x) - natural logarithm
LOG10(x)- decadical loagarithm
ABS(x) - absolute value
INT(x) - integer part
SQRT(x) - square root
SIGN(x) - Signum ( -1 if x<0, 0 if x=0, 1 if x>0 )
FACT(x) - Factorial ( x! )
INV(x) - Inversion ( 1/x )
With two parameters:
BAND(x1,y) - Bitwise AND
BOR(x1,y) - Bitwise OR
BXOR(x1,y) - Bitwise XOR
BSHIFT(x,i) - Bitwise SHIFT
Operators
---------
x+y - addition
x-y - substraction
x*y - multiplication
x/y - division
x^y - power
x**y - power (the same as ^)
Constants
---------
Pi - Pi = 3.14159265358979323846
e - Euler's number = 2.71828182846
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! x,y,i may be either numbers, constants or expressions !!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Error codes:
------------
0 - everything is OK, computed result returned
1 - function not followed by left bracket
2 - contains invalid function
3 - contains invalid charcter
4 - too few right brackets
5 - too few left brackets
6 - TAN not defined (i.e. TAN(Pi/2))
7 - COTG not defined (i.e. COTG(0))
8 - Fact(x) not defined : x < 0
9 - Fact(x) not defined : x is a decimal number
10 - Inv(x) not defined : x = 0
11 - Division by zero
12 - LogE(x) or Log10(x) not defined : x = 0
13 - Wrong number of parameters
Error codes 1..13 return zero as a result
Note: When I used Tan(pi/2) and similar non-defined functions (with Pi)
I had problems to detect these to provide the 6 & 7 errors.
This is caused by Cos(Pi/2) which doesn't return the exact value
of zero . So I decided to return these errors, when the result
of Sin(x) or Cos(x) is lower then 10e-15.
I havent't found a better way...
Examples
--------
Result = Eval('3+4*5*(1-sin(30*pi/180))-fact(sqrt(25)-2)*bshift(3,-1)',Err)
*** [ Result=7 ; Err=0] ***
----------------------------------------------------------------------------
Expr = '3+4*5*(1-sin(30*pi/180))-fact(sqrt(25)-2)*bshift(3,-1)'
Result = Eval(Expr,Err)
*** [ Result=7 ; Err=0] ***
----------------------------------------------------------------------------
Result = Eval('Band(14,5)^2*Log10(100)-2*Inv(Tan(pi/4))',Err)
*** [ Result=30 ; Err=0] ***
----------------------------------------------------------------------------
* if 1st condition = 'Yes'
* Expr = '(1'
* else
* Expr = '(0'
* .
*
* if 1st Logical operator = 'AND'
* Expr = Clip(Expr) & '*'
* else ! else
* Expr = Clip(Expr) & '+' ! OR
* .
*
* if 2nd condition = 'Yes'
* Expr = Clip(Expr) & '1)'
* else
* Expr = Clip(Expr) & '0)'
* .
*
* if 2nd Logical operator = 'AND'
* Expr = Clip(Expr) & '*'
* else ! else
* Expr = Clip(Expr) & '+' ! OR
* .
*
* if 3rd condition = 'Yes'
* Expr = Clip(Expr) & '1'
* else
* Expr = Clip(Expr) & '0'
* .
*
* Expr now looks like '(1+0)*1' or '(1*0)*1' or .... whatever
Result = Eval(Expr,Err)
*** [Result=0/1 depending on Expr; Err=0] ***
----------------------------------------------------------------------------
Result = Eval('5*3+',Err)
*** [Result=0; Err=13] ***
----------------------------------------------------------------------------
Result = Eval('5*Cos(Pi+3',Err)
*** [Result=0; Err=4] ***
----------------------------------------------------------------------------
etc...etc...etc...
I think that's all I want to say about functionality...
And now.....
****************
This tool is provided AS IS. I disclaim all warranties to this software
or documentation, whether express or implied.
There should be no malfunctions caused by Eval, but use it AT YOUR OWN RISK.
****************
As you may have noticed, there is no Copyright for this software.
Why?
I don't like when a programer makes utility primary for own usage, then
finds out that it works pretty well and decides to offer it as a shareware
with a registration fee of $xx which you have to pay if you want to us it.
I'm sorry, but I don't feel it to be a good idea...
Of course, I'd like to get some money (I am a student), but I think
it's much better to make commercial software for companies for profit
(as I do).
So, if you don't belong to the group I mentioned above, use this software
as long as you like it and find it useful. I give you ALL rights for
using it. You may use it either in your commercial software without any
registering. Generally said, do really WHATEVER you want with it.
If desired, the source code is also available !
Otherwise, if you do belong there, you have to contact me.
******** Finally Finish ********
Do you have any question, suggestion, wish, comment, reproachful word
or something you'd like to tell me ?
Feel free to write to me.
Excuse my English. I hope you understand everything...
Address :
Petr Langer
Jiráskova 1815
755 01 Vsetín
CZECH REPUBLIC
e-mail : p.langer@zlin.vutbr.cz or
langer@leo1.zlin.vutbr.cz